package com.stone.ai.robot.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/chat/ai")
public class ChatClientController {

    @Resource
    private ChatClient chatClient;



    @GetMapping(value = "/generateStream",produces = "text/html;charset=utf-8")
    public Flux<String> generate(@RequestParam(value = "message", defaultValue = "你是谁")String message
            ,@RequestParam(value = "chatId") String chatId) {

        return chatClient
                .prompt()
                .user(message)//提示词
                .advisors(a ->a.param(ChatMemory.CONVERSATION_ID,chatId)) // 添加对话ID
                .stream()//流式输出
                .content();
    }
}
